﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using Frame.Lib.Core.Role;
using Frame.Lib.Utilities;


namespace Jzy.Web.WorkFlow.Node
{
    public partial class SelectRole : System.Web.UI.Page
    {
        private RoleBO _role = new RoleBO();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindTree();
            }
        }

        private void BindTree()
        {
            List<RoleInfo> list = _role.GetList(RoleType.工作流);
            List<int> lstSelectIDs = StrUtil.SplitToInt(Request["SelectID"]);
            foreach (RoleInfo info in list)
            {
                TreeNode node = new TreeNode(info.Name, info.ID.ToString());
                node.SelectAction = TreeNodeSelectAction.Expand;
                if (lstSelectIDs.Contains(info.ID))
                {
                    node.Checked = true;
                }
                tvList.Nodes.Add(node);
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string values = "";
            string texts = "";
            TreeNodeCollection nodeCollection = tvList.CheckedNodes;
            foreach (TreeNode node in nodeCollection)
            {
                values += "," + node.Value;
                texts += "," + node.Text;
            }
            values = values.TrimStart(',');
            texts = texts.TrimStart(',');

            JSUtil.ReturnDlgValue(values, texts);
        }
    }
}
